<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>拆单列表页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta name="csrf-token" content="{{csrf_token()}}">
    @include('home.public.style')
    @include('home.public.script')
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" method="get" action="{{url('home/splitlist')}}">
                        <div class="layui-input-inline">
                            <select name="num" lay-filter="aihao">
                                <option value="" selected=""></option>
                                <option value="50" @if($request->input('num') == 50) selected="" @endif>50</option>
                                <option value="100" @if($request->input('num') == 100) selected="" @endif>100</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-inline">
                            <input type="text" name="orderno" style="width:250px" placeholder="请输入福禄订单号(支持模糊查询)"
                                   value="{{$request->input('orderno')?$request->input('orderno'):""}}"
                                   autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-inline">
                            <input type="text" name="account" style="width:250px" placeholder="请输入用户名(支持模糊查询)"
                                   value="{{$request->input('account')?$request->input('account'):""}}"
                                   autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i
                                        class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" method="get" action="{{url('home/excel/exportOrder')}}">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">导出excel</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
                    </button>
                    <b>当日成功:{{$count_today}}  当日失败:{{$count_today_false}}  累计充值:{{$count}}  累计失败:{{$count_false}}</b>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>
                                订单id
                            </th>
                            <th>充值账号</th>
                            <th>订单号</th>
                            <th>订单状态</th>
                            <th>推送状态</th>
                            <th>推送时间</th>
                            <th>完成时间</th>
                            <th>购买数量</th>
                            <th>订单价格</th>
                            <th>订单充值渠道</th>
                            <th>是否停用</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($order as $v)
                            <tr>
                                <td>
                                    {{$v->id}}
                                </td>
                                <td>{{$v->chargeaccount}}</td>
                                <td>{{$v->orderno}}</td>
                                <td>{{$v->status}}</td>
                                <td @if($v->branch == "已推送,等待反馈")style="color: royalblue" @elseif($v->branch == "充值失败") style="color: red" @elseif($v->branch == "已被获取，等回调") style="color: royalblue" @endif>{{$v->branch}}</td>
                                <td>{{date("Y-m-d H:i:s",intval($v->time))}}</td>
                                <td>{{date("i:s",intval($v->oktime))}}</td>
                                {{--<td></td>--}}
                                {{--<td></td>--}}
                                <td>{{$v->num}}</td>
                                <td>{{$v->remainingnumber}}</td>
                                <td>{{$v->bid}}</td>
                                <td class="td-status">
                                    <span class="layui-btn layui-btn-normal layui-btn-mini @if($v->isok == 2 || $v->isok==1) layui-btn-disabled  @endif">@if($v->isok == 2)
                                            已失败@elseif($v->isok == 1)已成功@else等回馈@endif</span>
                                </td>
                                <td class="td-manage">
                                    <a onclick="member_stop(this,'{{$v->id}}')" href="javascript:;"
                                       title="@if($v->isok == 2)已推送@else推送失败@endif">
                                        <i class="layui-icon">@if($v->isok == 1) &#xe63f; @else &#xe61f; @endif</i>
                                    </a>
                                    <a onclick="member_start(this,'{{$v->id}}')" href="javascript:;"
                                       title="@if($v->isok == 2)已推送@else推送成功@endif">
                                        <i class="layui-icon">@if($v->isok == 1) &#xe62f; @else &#xe61f; @endif</i>
                                    </a>
                                    <a onclick="check_status(this,'{{$v->orderno}}')" href="javascript:;"
                                       title="手动查询订单状态">
                                        <i class="layui-icon">@if($v->isok == 1) &#xe611; @else &#xe611; @endif</i>
                                    </a>
                                    <a title="编辑"
                                       onclick="xadmin.open('编辑','{{url('home/order/'.$v->id.'/edit')}}',600,400)"
                                       href="javascript:;">
                                        <i class="layui-icon">&#xe642; </i>
                                    </a>
                                    <a title="删除" onclick="member_del(this,'{{$v->id}}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {!! $order ->appends($request->all())->render() !!}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;


        // 监听全选
        form.on('checkbox(checkall)', function (data) {

            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
            ,type: 'datetime'
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
            ,type: 'datetime'
        });

    });

    /*用户-停用*/
    function member_stop(obj, id) {
        status = '推送失败';
        layer.confirm('确认要' + status + '吗？', function (index) {
            //发异步把用户状态进行更改
            $(obj).attr('title', '停用')
            $(obj).find('i').html('&#xe62f;');

            $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已失败');

            $.get("/home/branch/orderError",{'id':id},function(){
                layer.msg('已推送失败!', {icon: 5, time: 400}, function (data) {
                    // 可以对当前口进行刷新
                    location.reload();
                });
            })

        });
    }

    /*手动查询订单状态*/
    function check_status(obj, id) {
        layer.confirm('确认要' + status + '吗？', function (index) {
            $.get("/admin/push/getOrderInfo",{'id':id},function(){
                layer.msg('已推送失败!', {icon: 5, time: 400}, function (data) {
                    location.reload();
                });
            })

        });
    }

    /*用户-启用*/
    function member_start(obj, id) {
        status = '推送成功';
        layer.confirm('确认要' + status + '吗？', function (index) {
            //发异步把用户状态进行更改
            $(obj).attr('title', '停用')
            $(obj).find('i').html('&#xe62f;');

            $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已成功');

            $.get("/home/branch/orderSuccess",{'id':id},function(){
                layer.msg('已推送成功!', {icon: 5, time: 400}, function (data) {
                    // 可以对当前口进行刷新
                    location.reload();
                });
            })

        });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                method: 'delete',
                url: "/home/order/" + id,
                dateType: 'json',
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
                },
                success: function (data) {
                    layer.msg("删除成功", {
                            icon: 1,
                            time: 400 //2秒关闭（如果不配置，默认是3秒）
                        },
                        function () {
                            // 可以对当前口进行刷新
                            location.reload();
                        });
                },
            })
        });
    }


    function delAll(argument) {
        var ids = [];
        // 获取选中的id
        $('tbody input').each(function (index, el) {
            if ($(this).prop('checked')) {
                ids.push($(this).val())
            }
        });
        layer.confirm("确认要删除吗?", function () {
            $.ajax({
                type: 'post',
                url: "/home/order/delAll",
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
                },
                data: {ids: ids},
                success: function (data) {
                    layer.msg("删除成功", {
                        icon: 1,
                        time: 400 //2秒关闭（如果不配置，默认是3秒）
                    },
                    function () {
                        // 可以对当前口进行刷新
                        location.reload();
                    });
                },
            })
        });
    }

    function fresh_page(){
        window.location.reload();
    }

    setInterval('fresh_page()',30000);
</script>
</html>